﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GalaxyTranslator.EntityDataModel;
using GalaxyTranslator.Model;
using GalaxyTranslator.ViewInterfaces;

namespace GalaxyTranslator.Presenters
{
    public class AddOrderPresenter : BasePresenter<IAddOrderView>
    {
        public AddOrderPresenter(IAddOrderView view) : base(view)
        {
        }

        public void InitView(bool isPostBack)
        {
            if (!isPostBack)
            {
                InitLang();
            }
        }

        private void InitLang()
        {
            View.FromLanguages = DataLayer.GetAlLanguages();
            View.ToLanguages = DataLayer.GetAlLanguages();
        }

        public void AddOrder()
        {
            Order order = new Order
            {
                Created = DateTime.Now,
                Id_OriginalLang = View.SelectedFromLanguageId,
                Id_TranslateLang = View.SelectedToLanguageId,
                Id_Status = 1,
                Id_User = DataLayer.GetUserByName(View.MyselfName).Id,
                TextBeforeTranslation = View.TextToTranslate
            };
            DataLayer.AddNewOrder(order);
        }
    }
}